package cn.b.sky.mes.pp.service.impl;

import java.util.List;

import cn.b.sky.mes.pp.dao.ProductionOutputDao;
import cn.b.sky.mes.pp.model.ProductionOrder;
import cn.b.sky.mes.pp.model.condition.ProductionOutputCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.b.sky.common.utils.DateUtils;
import cn.b.sky.user.SecurityContextUtil;
import cn.b.sky.mes.pp.service.ProductionOutputService;

@Service
public class ProductionOutputServiceImpl implements ProductionOutputService {

  @Autowired
  ProductionOutputDao productionOutputDao;

  @Override
  public List<ProductionOrder> selectProductionsByCondition(ProductionOutputCondition condition) {
    if (null == condition) {
      condition = getCondition();
    }
    return productionOutputDao.selectProductionsByCondition(condition);
  }

  @Override
  public int selectProductionsCountByCondition(ProductionOutputCondition condition) {
    if (null == condition) {
      condition = getCondition();
    }
    return productionOutputDao.selectProductionsCountByCondition(condition);
  }

  @Override
  public List<ProductionOrder> selectAllProductionsByCondition(ProductionOutputCondition condition) {
    if (null == condition) {
      condition = getCondition();
    }
    return productionOutputDao.selectAllProductionsByCondition(condition);
  }

  private ProductionOutputCondition getCondition() {
    ProductionOutputCondition condition = new ProductionOutputCondition();
    condition.setSiteCode(SecurityContextUtil.getSiteCode());
    condition.setToDay(DateUtils.getDateUtils().getSystemStrDate());
    return condition;
  }
}
